<template>
    <div class="bankingInformationPage">
        <div class="search-wrap d-flex a-center">
            <div class="search-item d-flex a-center m-l20">
                <label>机构名称</label>
                <el-select class="m-l10" v-model="form.companyId" clearable>
                    <el-option v-for="(item,index) in companyList" :key="index" :label="item.companyName" :value="item.companyId"></el-option>
                </el-select>
            </div>
            <div class="search-item d-flex a-center m-l20">
                <label>开户行</label>
                <el-select class="m-l10" v-model="form.bankAccountId" clearable>
                    <el-option v-for="(item,index) in bankAccountList" :key="index" :label="item.bankName" :value="item.bankAccountId"></el-option>
                </el-select>
            </div>
            <div class="search-item d-flex a-center m-l20">
                <label>账户类型</label>
                <el-select class="m-l10" v-model="form.accountType" clearable>
                    <el-option label="基本户" value="1"></el-option>
                    <el-option label="一般户" value="2"></el-option>
                </el-select>
            </div>
            <div class="search-buttons m-l50 d-flex a-center">
                <el-button
                        color="#fc702b"
                        style="color:#fff;"
                        @click.prevent="onQuery"
                >查询</el-button>
                <el-button
                        color="#f0f0f0"
                        style="color: #000000"
                        @click.prevent="onReset"
                >重置</el-button>
                <el-divider direction="vertical" />
                <el-button @click="toPage" class="button_edit m-r10">
                    查看余额
                </el-button>
                <el-button class="button_edit" @click="onExport">
                    <svg-icon icon-class="project-detail-icon-derive" class="icon-export m-r5"></svg-icon>
                    一键导出
                </el-button>
            </div>
        </div>
        <public-table
                ref="publicTableRef"
                class="m-t20"
                index
                :indexWidth="'100'"
                :page="page"
                :tableData="tableData"
                :tableOption.sync="tableOption"
                @page-change="onPageChange"
        >
            <template #bankName="scope">
                <span
                    style="cursor: pointer;color: #fc7037;"
                    @click="queryBank(scope.row)"
                >{{scope.row.bankName}}</span>
            </template>
        </public-table>
    </div>

    <public-dialog
        title="银行信息"
        width="30%"
        v-model:visible="bankVisible"
        :footer-button="false"
    >
        <el-form class="m-l20 m-r20">
            <el-form-item label="机构名称">
                <el-input disabled :placeholder="bankInfo.companyName"></el-input>
            </el-form-item>
            <el-form-item label="开户银行">
                <el-input disabled :placeholder="bankInfo.bankName"></el-input>
            </el-form-item>
            <el-form-item label="账户性质">
                <el-input disabled :placeholder="{'1':'基本户','2':'一般户'}[bankInfo.accountType] || '暂无'"></el-input>
            </el-form-item>
            <el-form-item label="账户用途">
                <el-input disabled :placeholder="bankInfo.accountPurpose"></el-input>
            </el-form-item>
            <el-form-item label="账户号码">
                <el-input disabled :placeholder="bankInfo.bankAccountNumber"></el-input>
            </el-form-item>
            <el-form-item label="账户归属">
                <el-input disabled :placeholder="{'1':'本部','2':'子公司'}[bankInfo.accountOwnership]"></el-input>
            </el-form-item>
            <el-form-item label="账户类型">
                <el-input disabled :placeholder="{'1':'开立'}[bankInfo.bankType]"></el-input>
            </el-form-item>
            <el-form-item label="账户余额">
                <el-input disabled :placeholder="bankInfo.bankBalance || 0"></el-input>
            </el-form-item>
        </el-form>
    </public-dialog>
</template>

<script setup>
import {onMounted, reactive, ref} from "vue";
import {
    ElSelect,
    ElOption,
    ElDivider,
    ElForm,ElFormItem
} from "element-plus";
import PublicTable from "@/components/PublicTable.vue";

import {tableCommonFun} from "@/hooks/tableCommon";
import {bankManagementApi, companyApi} from "@/api/businessFinance";
import {useRouter} from "vue-router";
import PublicDialog from "@/components/PublicDialog.vue";

const interfaceConfig = reactive({
    fileName:'businessFinance',
    apiPath:'companyApi.getBankCompany',
});
const exportConfig = reactive({
    fileName:'businessFinance',
    apiPath:'exportApi.getBankCompanyLeadingOut',
    tableName:'银行信息表'
});
const {
    form,
    page,
    tableOption,
    tableData,
    onQuery,
    onReset,
    onPageChange,
    getData,
    onExport
}  = tableCommonFun(interfaceConfig,exportConfig);

form.value = {
    companyId: '',
    bankAccountId: '',
    accountType: ''
}

tableOption.value = [
  { label: "机构名称 ", prop: "companyName", minWidth: 150 },
  { label: "开户行", prop: "bankName", slot: true, minWidth: 120 },
  {
    label: "账号类型", prop: "accountType", formatter: (val, row) => {
      return ['', '基本户', '一般户'][val] || '-';
    }, minWidth: 100
  },
  { label: "账户用途", prop: "accountPurpose", minWidth: 100 },
  { label: "银行账户号", prop: "bankAccountNumber", minWidth: 120 },
  {
    label: "账户归属", prop: "accountOwnership", minWidth: 100, formatter: (val, row) => {
      // 1:本部 2:子公司
      return { 1: "本部", 2: "子公司" }[val];
    }
  },
  {
    label: "银行类型", prop: "bankType", formatter: (val, row) => {
      return ['', '开立'][val];
    }, minWidth: 100
  },
];


const companyList = ref([]);
/**
 * 查公司列表
 */
const getCompanyList = () => {
    companyApi.getList({}).then(res=>{
        companyList.value = res.data;
    });
}

/**
 * 查询银行列表
 *
 */
const bankAccountList = ref([]);
const getBankList = () => {
    companyApi.getBankList().then(res=>{
        if(res.code === '200'){
          bankAccountList.value = res.data;
        }
    });
}

/**
 * 跳转银行余额页面
 */
const router = useRouter();
const toPage = () => {
    router.push({path:`/businessFinance/bankManagement/bankInformation/bankBalance`});
}

/**
 * 查询银行信息
 * @param row
 */
const bankVisible = ref(false);
const bankInfo = ref({});
const queryBank = (row) => {
    bankVisible.value = true;
    bankManagementApi.getBankCompanyInfo(row.bankAccountId).then(res=>{
        if(res.code === '200'){
            bankInfo.value = res.data;
        }
    });
}


onMounted(()=>{
    getData({
        pageNum:1,
        pageSize:10
    });
    getCompanyList();
    getBankList();
});
</script>

<style lang="scss" scoped>
.el-form-item{
    width: 100% !important;
}
.bankingInformationPage{
  .search-wrap{
    .search-item{

      .el-input{
        width: auto !important;
      }
    }
    .search-buttons{
      .icon-export{
        width: 18px;
        height: 18px;
      }
    }
  }
}
.public-dialog-content{
  .dialog-title-box{
    height: 30px;
    span{
      font-size: 15px;
      font-weight: 600;
    }
  }
}
</style>
